package com.suse.lhw.hms.exersiseserver.service.Impl;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.suse.lhw.hms.exersiseserver.domin.ECollection;
import com.suse.lhw.hms.exersiseserver.dao.ECollectionMapper;
import com.suse.lhw.hms.exersiseserver.service.ECollectionService;

import java.util.Date;

/**
 * @ProjectName: health_manage_system
 * @Package: com.suse.lhw.hms.exersiseserver.service.Impl
 * @ClassName: ECollectionServiceImpl
 * @Description: java类作用描述
 * @Author: 李鸿炜
 * @CreateDate: 2020/5/6 0:23
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/5/6 0:23
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Service
public class ECollectionServiceImpl implements ECollectionService {

    @Resource
    private ECollectionMapper eCollectionMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return eCollectionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(ECollection record) {
        return eCollectionMapper.insert(record);
    }

    @Override
    public int insertSelective(ECollection record) {
        return eCollectionMapper.insertSelective(record);
    }

    @Override
    public ECollection selectByPrimaryKey(Integer id) {
        return eCollectionMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(ECollection record) {
        return eCollectionMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(ECollection record) {
        return eCollectionMapper.updateByPrimaryKey(record);
    }

    @Override
    public int collectByUseridTypeCollectionId(int modelId, int type, String userId) {
        //创建一个收集
        ECollection eCollection = new ECollection();
        eCollection.setUserid(userId);
        eCollection.setType(type);
        eCollection.setCollectionid(modelId);
        eCollection.setCreattime(new Date());
        if (eCollectionMapper.insert(eCollection) == 0)
            return 0;
        return 1;
    }

    @Override
    public int cancelByUseridCid(String userId, int modelId) {
        //取消收藏，直接删除
        ECollection eCollection = eCollectionMapper.selectByUserIdAndCid(userId, modelId);
        if (eCollectionMapper.deleteByPrimaryKey(eCollection.getId()) == 0)
            return 0;
        return 1;
    }
}
